<?php
/**
 * Content controller. Displays content pages
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @category VaselinEngine
 * @package Content Module
 * @subpackage Controller
 * @license  New BSD License
 *
 */
class content_ContentController extends Bel_Controller {
	
	/**
	 * Pages model object
	 *
	 * @var Models_Content_Pages
	 */
	private $_pages;
	
	/**
	 * Initialization
	 *
	 */
	public function init() {
		$this->_pages = new Models_Content_Pages ( );
		parent::init ();
	}
	
	/**
	 * Displays content page
	 *
	 */
	public function indexAction() {
		
		if (! ($page_data = $this->_cache->load ( 'page_'.str_replace('-','_',$this->_request->getParam('page_system_name')) ))) {
			$page_data = $this->_pages->getPageBySystemName ( $this->_request->getParam ( 'page_system_name' ) );
			$this->_cache->save ( $page_data );
		}		

		if (! $page_data) {
			$this->_response->setHeader ( 'HTTP/1.x', '404 Not found' );
			$this->_response->clearBody ();
			$this->view->display ( '404.tpl' );
			$this->_response->sendHeaders ();
		}else{
		
			$this->_seo->setTitle ( $page_data ['page_title'] );
			$this->_seo->setDescription ( $page_data ['page_description'] );
			$this->_seo->setKeywords ( $page_data ['page_keywords'] );
		
			$this->view->assign ( 'page_content', $page_data );
			$this->view->display ( 'content/content_page.tpl' );
		}
	}

}